package xyz.chaobei.date;

import java.time.DayOfWeek;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoField;
import java.util.Date;

/**
 * @author <a href='mailto:maruichao52@gmail.com'>MRC</a>
 * @since 2021/2/19
 */
public class LocalDateTimeTest {

    public static void main(String[] args) {

        LocalDateTime dateTime = LocalDateTime.now();
        System.out.println("1: 当前日期时间=" + dateTime.toString());

        DayOfWeek dayOfWeek = dateTime.getDayOfWeek();
        System.out.println("2: 当前周内表示=" + dayOfWeek.name());

        int dayOfMonth = dateTime.getDayOfMonth();
        System.out.println("3: 当前月内表示=" + dayOfMonth);

        long dayOfYear = dateTime.getLong(ChronoField.DAY_OF_YEAR);
        System.out.println("4: 当前年内天数=" + dayOfYear);

        // 附加时区，转换为实例
        Instant instant = dateTime.atZone(ZoneId.systemDefault()).toInstant();

        Date date = Date.from(instant);
        System.out.println("4: 转换为旧date=" + date.toString());

        LocalDateTime yesterday = LocalDateTime.of(2021,3,9,21,59,59);
        System.out.println("5: 指定时间昨天=" + yesterday.toString());

        LocalDateTime now = LocalDateTime.now();

        System.out.println("5: 当前时间在昨天之后=" + now.isAfter(yesterday));
    }

}
